<template>
  <div class="login-container">
    <video
      class="video"
      muted
      src="../../assets/video/bg.mp4"
      loop="loop"
      autoplay="true"
    ></video>
    <el-form
      :model="loginForm"
      status-icon
      :rules="rules"
      ref="loginForm"
      label-width="100px"
      class="demo-loginForm"
    >
      <h1 class="title">千锋管理系统</h1>
      <i :class="['jiaobiao', 'iconfont']"></i>

      <!-- 账号 -->
      <commomLogin
        @syncLogForm="handleSyncLoginForm"
        @submit="submit"
      ></commomLogin>

      <!-- 二维码 -->
      <!-- <qrLogin></qrLogin> -->
      <!-- <link rel="stylesheet" href="//at.alicdn.com/t/font_2401295_ftowz2j10vp.css"> -->

      <!-- 短信 -->
      <!-- <smsLogin></smsLogin> -->
    </el-form>
  </div>
</template>

<script>
var validateCaptcha = (rule, value, callback) => {
  if (value.length !== 5) {
    callback("验证码必须是五位");
  } else {
    callback();
  }
};
var validateUseername = (rule, value, callback) => {
  var usernames = /^\w{3,12}$/;
  if (usernames.test(value)) {
    callback();
  } else {
    callback("3-12字母数字下划线");
  }
};
var validatePassword = (rule, value, callback) => {
  var passwords = /^[a-z0-9_-]{3,20}$/;
  if (passwords.test(value)) {
    callback();
  } else {
    callback("请输入密码");
  }
};
import commomLogin from "./commonLogin.vue";
// import qrLogin from "./qrLogin.vue";
// import smsLogin from "./smsLogin.vue";
import * as api from "@/api/users";
export default {
  data() {
    return {
      isSmsLogin: true,
      loginForm: {
        username: "",
        password: "",
        captcha: ""
      },
      rules: {
        username: [{ validator: validateUseername, trigger: "blur" }],
        password: [{ validator: validatePassword, trigger: "blur" }],
        captcha: [{ validator: validateCaptcha, trigger: "blur" }]
      }
    };
  },

  components: {
    commomLogin,
    // qrLogin,
    // smsLogin
  },
  methods: {
    handleSyncLoginForm(newLoginForm) {
      console.log(newLoginForm);
      this.loginForm = newLoginForm;
    },
    submit() {
      this.$refs["loginForm"].validate(valid => {
        if (valid) {
          alert('submit!');
          api.verifyCaptcha(this.loginForm.captcha).then(res => {
            if (res.data.state) {
            } else {
              this.$refs["commonLogin"].getCaptcha();
            }
          });
        } else {
          console.log("error submit");
          return false;
        }
      });
    }
  }
};
</script>

<style scoped lang="less">
/deep/.el-form-item__label {
  color: #fff;
}
.icon-wx {
  width: 25px !important;
  height: 25px !important;
  vertical-align: -7px;
  margin-right: 3px;
}
.login-container {
  text-align: center;
  color: #fff;
  .common-login {
    padding-right: 50px;
  }

  .erwei .img {
    display: inline-block;
    position: relative;
    width: 200px;
    height: 200px;
    img {
      position: absolute;
      left: 0;
    }

    .mask {
      width: 100%;
      height: 100%;
      opacity: 0.8;
      background-color: #fff;
      position: absolute;
      left: 0;
      // background-image: url("../../");
      background-size: 50%;
      background-repeat: no-repeat;
      background-position: center;
      cursor: pointer;
    }
  }

  .jiaobiao {
    font-size: 60px;
    color: #fff;
    position: absolute;
    right: -1px;
    top: -1px;
  }

  .video {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
  }

  .el-form {
    border-radius: 4px;
    background-color: rgba(0, 0, 0, 0.3);
    width: 400px;
    position: fixed;
    right: 10%;
    top: 25%;
    padding: 100px 0 50px 0;

    /deep/.el-input__inner {
      width: 250px;
    }
    /deep/.el-button--primary {
      background: blue;
      width: 250px;
    }

    .title {
      margin: 0 0 60px 0;
      text-align: center;
      color: #fff;
    }
  }
}

.smsContainer {
  padding-right: 20px !important;
  width: 89%;
  /deep/ .el-form-item__label {
    margin-left: 80px !important;
    padding: 0 !important;
    padding-right: 10px !important;
  }
  /deep/ .phone {
    width: 140px !important;
  }
  /deep/ .captcha-svg {
    width: 115px !important;
  }
  /deep/ .el-form-item__content {
    margin: 0;
  }
}
</style>

<!-- <style lang="less" scoped>
.login-container {
  .demo-loginForm {
    border-radius: 4px;
    background-color: rgba(0, 0, 0, 0.3);
    width: 400px;
    position: fixed;
    right: 10%;
    top: 20%;
    padding: 100px 0 50px 0;
    .title {
      text-align: center;
      margin-bottom: 50px;
      color: #fff;
    }
  }
  .video {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
  }
}
</style> -->
